home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.02 Feb 91 / Menu Bar Sources / ShowHideMBar.p < prev   
Encoding:
Text File  |  1989-10-17  |  4.8 KB  |  216 lines  |  [TEXT/MPS ]

  1. {
  2. ShowHideMBar.p
  3. MPW 3.0 Pascal unit to hide the menu bar
  4. Copyright © 1989 D. Grant Leeper.
  5. All rights reserved.
  6. Publication rights granted to MacTutor.
  7.  
  8. NOTE: The calling application is responsible for
  9. insuring that the menu bar is left visible after
  10. suspending and quitting!
  11.  
  12. CAUTION: This code violates the guidelines for
  13. future compatibility, use it at your own risk.
  14. Specifically it modifies the GrayRgn and
  15. MBarHeight global variables, and paints and
  16. manipulates the window manager port.
  17. Also, since it modifies MBarHeight it requires
  18. the 128K (or newer) ROMs.
  19. }
  20.  
  21. UNIT ShowHideMBar;
  22.  
  23. INTERFACE
  24.  
  25. USES
  26.     Types, QuickDraw, Events,
  27.     Controls, Windows, Menus;
  28.  
  29. PROCEDURE HideMenuBar;
  30.  
  31. PROCEDURE ShowMenuBar;
  32.  
  33. FUNCTION  MenuBarVisible: BOOLEAN;
  34.  
  35. FUNCTION  PtInMenuBar(pt: Point): BOOLEAN;
  36.  
  37. FUNCTION  HiddenMenuSelect
  38.             (startPt: Point): LONGINT;
  39.  
  40. IMPLEMENTATION
  41.  
  42. VAR
  43.     gSavedMBarHeight:    INTEGER;
  44. (*
  45. CONST
  46.     GrayRgn =        $09EE;
  47.     MBarHeight =    $0BAA;
  48.  
  49. { Defined in Windows.p }
  50. FUNCTION  GetGrayRgn: RgnHandle;
  51.     INLINE $2EB8, $09EE; { MOVE.L GrayRgn,(SP) }
  52. *)
  53. { Defined in Script.p }
  54. FUNCTION  GetMBarHeight: INTEGER;
  55.     INLINE $3EB8, $0BAA; { MOVE MBarHeight,(SP) }
  56.  
  57. PROCEDURE SetMBarHeight(height: INTEGER);
  58.     INLINE $31DF, $0BAA; { MOVE (SP)+,MBarHeight }
  59.  
  60. FUNCTION  GetWindowList: WindowPtr;
  61.     INLINE $2EB8, $9D6; { MOVE.L WindowList,(SP) }
  62.  
  63. {$S ShowHideMBar}
  64. FUNCTION  GetMBarRgn: RgnHandle;
  65.  
  66.     VAR
  67.         r:            Rect;
  68.         worldRgn:    RgnHandle;
  69.         mBarRgn:    RgnHandle;
  70.     
  71.     BEGIN
  72.     { Compute worldRgn, the round cornered
  73.       rectangle that bounds all screens }
  74.     r := GetGrayRgn^^.rgnBBox;
  75.     UnionRect(r, screenBits.bounds, r);
  76.     worldRgn := NewRgn;
  77.     OpenRgn;
  78.     FrameRoundRect(r, 16, 16);
  79.     CloseRgn(worldRgn);
  80.     
  81.     { Compute mBarRgn, the intersection
  82.       of the menu bar's rectangle with
  83.       worldRgn. }
  84.     r := screenBits.bounds;
  85.     r.bottom := r.top + gSavedMBarHeight;
  86.     mBarRgn := NewRgn;
  87.     RectRgn(mBarRgn, r);
  88.     SectRgn(worldRgn, mBarRgn, mBarRgn);
  89.     
  90.     DisposeRgn(worldRgn);
  91.     GetMBarRgn := mBarRgn
  92.     END; { GetMBarRgn }
  93.  
  94. {$S ShowHideMBar}
  95. PROCEDURE HideMenuBar;
  96.     
  97.     VAR
  98.         mBarHeight:        INTEGER;
  99.         grayRgn:        RgnHandle;
  100.         menuBarRgn:        RgnHandle;
  101.         startWindow:    WindowPeek;
  102.  
  103.     BEGIN
  104.     mBarHeight := GetMBarHeight;
  105.     IF mBarHeight <> 0 THEN
  106.         BEGIN
  107.         grayRgn := GetGrayRgn;
  108.         { GSavedMBarHeight must be valid
  109.           when calling GetMBarRgn }
  110.         gSavedMBarHeight := mBarHeight;
  111.         menuBarRgn := GetMBarRgn;
  112.         SetMBarHeight(0);
  113.         { Add menuBarRgn to GrayRgn. }
  114.         UnionRgn(grayRgn, menuBarRgn, grayRgn);
  115.         { Now tell the Window Manager that the
  116.           desktop has expanded, so the area
  117.           under the menu bar will get
  118.           updated correctly.  We do this by
  119.           calling two of the low-level
  120.           Window Manager routines PaintBehind
  121.           and CalcVisBehind. }
  122.         startWindow := WindowPeek(GetWindowList);
  123.         { PaintBehind redraws the desktop,
  124.           including window frames, as made
  125.           necessary by the removal of the menu
  126.           bar.  It also generates the needed
  127.           window update events. }
  128.         PaintBehind(startWindow, menuBarRgn);
  129.         { CalcVisBehind recalculates any window
  130.           visRgns that need to be changed to
  131.           allow for the removal of the menu bar. }
  132.         CalcVisBehind(startWindow, menuBarRgn);
  133.         DisposeRgn(menuBarRgn)
  134.         END { IF }
  135.     END; { HideMenuBar }
  136.  
  137. {$S ShowHideMBar}
  138. PROCEDURE ShowMenuBar;
  139.     
  140.     VAR
  141.         grayRgn:    RgnHandle;
  142.         menuBarRgn:    RgnHandle;
  143.     
  144.     BEGIN
  145.     IF GetMBarHeight = 0 THEN
  146.         BEGIN
  147.         grayRgn := GetGrayRgn;
  148.         menuBarRgn := GetMBarRgn;
  149.         SetMBarHeight(gSavedMBarHeight);
  150.         { Remove menuBarRgn from GrayRgn }
  151.         DiffRgn(grayRgn, menuBarRgn, grayRgn);
  152.         { Now tell the Window Manager that the
  153.           menu bar is no longer part of the
  154.           desktop.  We do this by calling
  155.           CalcVisBehind again.  We do not need
  156.           to call PaintBehind first because we
  157.           are not expanding the desktop. }
  158.         CalcVisBehind(WindowPeek(GetWindowList),
  159.                       menuBarRgn);
  160.         DisposeRgn(menuBarRgn);
  161.         { Now redraw the menu bar on the
  162.           desktop. }
  163.         DrawMenuBar
  164.         END { IF }
  165.     END; { ShowMenuBar }
  166.  
  167. {$S ShowHideMBar}
  168. FUNCTION  MenuBarVisible: BOOLEAN;
  169.  
  170.     BEGIN
  171.     MenuBarVisible := GetMBarHeight <> 0
  172.     END; { MenuBarVisible }
  173.  
  174. {$S ShowHideMBar}
  175. FUNCTION  PtInMenuBar(pt: Point): BOOLEAN;
  176.  
  177.     VAR
  178.         height:    INTEGER;
  179.         r:        Rect;
  180.     
  181.     BEGIN
  182.     height := GetMBarHeight;
  183.     IF height = 0 THEN
  184.         { Menu bar is hidden. }
  185.         height := gSavedMBarHeight;
  186.     r := screenBits.bounds;
  187.     r.bottom := r.top + height;
  188.     PtInMenuBar := PtInRect(pt, r)
  189.     END; { PtInMenuBar }
  190.  
  191. {$S ShowHideMBar}
  192. FUNCTION  HiddenMenuSelect
  193.             (startPt: Point): LONGINT;
  194.  
  195.     VAR
  196.         wasHidden:    BOOLEAN;
  197.     
  198.     BEGIN
  199.     wasHidden := GetMBarHeight = 0;
  200.     IF wasHidden THEN
  201.         { Change it temporarily. }
  202.         SetMBarHeight(gSavedMBarHeight);
  203.     { Now do normal MenuSelect }
  204.     HiddenMenuSelect := MenuSelect(startPt);
  205.     IF wasHidden THEN
  206.         BEGIN
  207.         { We must unhilite the menu ourselves
  208.           before setting MBarHeight back to 0. }
  209.         HiliteMenu(0);
  210.         { Now change it back. }
  211.         SetMBarHeight(0)
  212.         END { IF }
  213.     END; { HiddenMenuSelect }
  214.  
  215. END. { ShowHideMBar }
  216.